var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var index = require('./routes/index');
var users = require('./routes/users');
// var multipart = require('connect-multiparty');
// var multipartMiddleware = multipart();
var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set("view engine", "ejs");



// 处理 form-data 请求 字符串拼接
// app.use(multipartMiddleware);
// app.use(multiparty({uploadDir:'./temp' }));//设置上传文件存放的地址。
// 处理 x-www-form-urlencoded 请求  字符串拼接
app.use(bodyParser.urlencoded({ extended: false }));
//静态资源过滤 直接走public文件夹
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'uploads')));


app.use('/', index);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};
  // render the error page
  res.status(err.status || 500);
  console.log("尝试进入error页");
  console.log(err);
  res.render('error');
});


// module.exports = app;
app.listen(3000);
